from pywinauto.application import Application, WindowSpecification
import pywinauto
from pywinauto.keyboard import send_keys

# Application(backend="uia").start(r"C:\Program Files (x86)\Morningstar\Direct\MStarAWD.exe")
# app = Application().connect(path=r"C:\Program Files (x86)\Morningstar\Direct\MStarAWD.exe")
app = Application().connect(handle=592338)
# app = Application().connect(process=17224)
# Morningstarapp = Application().connect(handle=4722570)
# wd = wd.wait('visible')
# print(app.windows())
# ------------获取窗口-----------------
# dlg = app["Morningstar DirectDialog"]
# print(dlg.print_control_identifiers())
# --------------截图-----------------
# dlg_c = dlg.child_window(title="Chrome Legacy Window", class_name="Chrome_RenderWidgetHostHWND")
# pic = dlg.capture_as_image()
# pic2 = dlg_c.capture_as_image()
# pic.save("01.png")
# pic2.save("02.png")
# -----------窗口最大化----------------
# dlg.maximize()
# -----------窗口最小化----------------
# dlg.minimize()
# -----------恢复窗口原大小----------------
# dlg.restore()
# -----------获取窗口坐标----------------
# print(dlg.rectangle())
# ------查看窗口上所有控件-------
# print(dlg.print_control_identifiers())
# ------控件类型-------
# print(dlg.wrapper_object())
# ------通过child_window方法获取子空间-------"
# dlg_cw = dlg.child_window(title="Sign In to Morningstar", class_name="Chrome_WidgetWin_1")
# print(dlg_cw.print_control_identifiers())
# --------获取控件支持的方法----------
# print(dir(dlg.wrapper_object()))
# ----------查看控件文本内容--------
# print(dlg.texts())
# ----------查看控件的子元素---------
# print(dlg.children())
# ----------查看控件的类名---------
# print(dlg.class_name)
# -----------查看控件的属性---------
# print(dlg.properties)
# print(dlg.exists())

dlg03 = app['Chrome Legacy Window']
print(dlg03.exists())

# dlg["mds-input___ctrsi"].type_keys("22222222222222222222222222222")
# print(dlg["Chrome Legacy Window"].print_control_identifiers(), "5555555555555555555")
# print(dlg, "33333333333333333333333333333")
# print("-------------------------------------------------------")
# print(dlg.print_control_identifiers())
# print(dlg["Dialog"], "44444444444444")
# app["Dialog"].print_control_identifiers(), "44444444444444"
# dlg2 = dlg['Sign In to Morningstar']
# print(dlg2.print_control_identifiers())
# dlg['Email'].type_keys("kkdsjfksdjkfks")

# dlg.child_window(class_name="mds-input___ctrsi mds-input--large___ctrs").click()
# send_keys("4444444444444444444444444444")
# print(app["Morningstar Direct"]["Chrome Legacy Window"].print_control_identifiers())
# print(app["Morningstar Direct"]['Chrome_WidgetWin_1'].print_control_identifiers())
# wd.child_window(AutomationId="emailInput").type_keys("23333333333333333333333333")
